package com.panda.springcloud.controller;/**
 * @author 乐于吕
 * * @date 2024/10/23
 */

import com.panda.springcloud.entity.City;
import com.panda.springcloud.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *@Author: 乐于吕
 *@CreateTime: 2024-10-23
 *@Description:
 */

@RestController
@RequestMapping("/cities")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping()
    public List<City> cityList(){
        return cityService.list();
    }

    @GetMapping("{id}")
    public City getCityById(@PathVariable("id") Integer id){
        return cityService.getById(id);
    }

    @PostMapping()
    public  City addCity(@RequestBody City city){
        //保存城市信息
        cityService.save(city);
        return city;
    }


}
